package com.link.base.task;

import com.link.base.base.esb.service.LinkBaseDataApiService;
import com.link.base.core.basic.config.xxljob.BaseLinkJobHandler;
import com.link.core.util.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 更新应收单发票
 * 
 * @author 王昊
 * @date 2021/05/24 09:52
 */
@JobHandler(value = "returnInfoJobHandler")
@Component
public class TaskReturnInfoFromERP extends BaseLinkJobHandler {

    @Resource
    private LinkBaseDataApiService linkBaseDataApiService;

    @Override
    public ReturnT<String> execute(String params) throws Exception {
        try {
            // XxlJobLogger 打印的日志会体现在调度中心的执行日志中
            XxlJobLogger.log("XXL-JOB,收款单信息更新开始...");
            XxlJobLogger.log("收款单信息更新开始时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            // 调用父的方法设置登录信息
            super.setLogin(params);
            linkBaseDataApiService.upsertReturnInfoFromERP();
            XxlJobLogger.log("收款单信息更新结束时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log(e.getMessage());
            return ReturnT.FAIL;
        }
    }

}
